
#include "rtpaac.h"
#include "public_def.h"

//Make RTP packet 
//
//Parameter:
//	hdr					reference of the RTP header
//	pAStream			reference of audio stream
//
//Return:
//	None
//
static void AAC_Make_Payload(RTPHeader_t *hdr, RTP_AStream_t *pAStream)
{
	RTPHeader_t * pRtpHdr = &pAStream->pRTPHdr;
	RTP_HDR_SET_VERSION(pRtpHdr, RTP_VERSION);
	RTP_HDR_SET_P(pRtpHdr, 0);
	RTP_HDR_SET_X(pRtpHdr, 0);
	RTP_HDR_SET_CC(pRtpHdr, 0);
	RTP_HDR_SET_M(pRtpHdr, hdr->marker);
	RTP_HDR_SET_PT(pRtpHdr, hdr->pt);
	RTP_HDR_SET_SEQNO(pRtpHdr, htons(hdr->seqno));
	RTP_HDR_SET_TS(pRtpHdr, htonl(hdr->ts));
	RTP_HDR_SET_SSRC(pRtpHdr, htonl(hdr->ssrc));
}



void AAC_RTP_Packet(void *pHdr, RTP_AStream_t *pAStream, OnRTP_HandleStream_Callback pFunc, void *param, int _iTimestap)
{
	RTPHeader_t *hdr = (RTPHeader_t *)pHdr;
	AAC_Make_Payload(hdr, pAStream);

	if (hdr->seqno >= 0xFFFF)
	{
		hdr->seqno = 0;
	}
	else
	{
		hdr->seqno++;
	}
	
	hdr->ts =_iTimestap *48;
	
	//hdr->ts += 24;
	if(pFunc != NULL)
	{
		pFunc(pAStream, pAStream->usLength+ RTP_HDR_LEN, param);
	}	
}

